<template>
  <div class="finance-income-page">
    <el-card class="income-card">
      <template #header>
        <div class="card-header">
          <span>收入单管理</span>
          <el-button type="primary" @click="handleAdd" v-if="hasPerm('finance:income:add')">新增收入单</el-button>
        </div>
      </template>
      
      <el-table :data="incomeList" style="width: 100%">
        <el-table-column prop="incomeCode" label="收入单号" width="120" />
        <el-table-column prop="customerName" label="客户名称" width="150" />
        <el-table-column prop="amount" label="收入金额" width="120">
          <template #default="scope">
            ¥{{ scope.row.amount.toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column prop="type" label="收入类型" width="100" />
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag :type="getStatusType(scope.row.status)">
              {{ getStatusText(scope.row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="创建日期" width="120" />
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button size="small" @click="handleView(scope.row)" v-if="hasPerm('finance:income:view')">查看</el-button>
            <el-button size="small" type="primary" @click="handleEdit(scope.row)" v-if="hasPerm('finance:income:edit')">编辑</el-button>
            <el-button size="small" type="success" @click="handleSubmit(scope.row)" v-if="hasPerm('finance:income:submit')">提交</el-button>
            <el-button size="small" type="warning" @click="handleAudit(scope.row)" v-if="hasPerm('finance:income:audit')">审核</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.row)" v-if="hasPerm('finance:income:delete')">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { hasPerm } from '@/utils/permission'
import { ElMessage } from 'element-plus'

const incomeList = ref([])

const getStatusType = (status) => {
  const statusMap = {
    'draft': 'info',
    'submitted': 'warning',
    'audited': 'success',
    'rejected': 'danger'
  }
  return statusMap[status] || 'info'
}

const getStatusText = (status) => {
  const statusMap = {
    'draft': '草稿',
    'submitted': '已提交',
    'audited': '已审核',
    'rejected': '已驳回'
  }
  return statusMap[status] || '未知'
}

const handleAdd = () => {
  ElMessage.info('新增收入单功能')
}

const handleView = (row) => {
  ElMessage.info(`查看收入单：${row.incomeCode}`)
}

const handleEdit = (row) => {
  ElMessage.info(`编辑收入单：${row.incomeCode}`)
}

const handleSubmit = (row) => {
  ElMessage.info(`提交收入单：${row.incomeCode}`)
}

const handleAudit = (row) => {
  ElMessage.info(`审核收入单：${row.incomeCode}`)
}

const handleDelete = (row) => {
  ElMessage.info(`删除收入单：${row.incomeCode}`)
}

onMounted(() => {
  // 模拟数据
  incomeList.value = [
    {
      incomeCode: 'INC001',
      customerName: '客户A',
      amount: 10000.00,
      type: '销售收入',
      status: 'draft',
      createDate: '2025-07-30'
    },
    {
      incomeCode: 'INC002',
      customerName: '客户B',
      amount: 5000.00,
      type: '服务收入',
      status: 'submitted',
      createDate: '2025-07-29'
    },
    {
      incomeCode: 'INC003',
      customerName: '客户C',
      amount: 15000.00,
      type: '销售收入',
      status: 'audited',
      createDate: '2025-07-28'
    }
  ]
})
</script>

<style scoped>
.finance-income-page {
  padding: 20px;
}

.income-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 